<?php
/**
 * 
 */
namespace app\home\controller\consult;

use app\home\controller\Base;

class Handle extends Base
{

	private $params;

	public function __construct(){
		parent::__construct();
		// token验证
		if(false == Base::checkToken()){
			$this->error('token error!');
		}
		// 参数去token
		//$params = $this->request->post();
		$params = input('post.');
		unset($params['token']);
		$this->params = $params;
	}

	public function submit(){
		$params = $this->params;

		$pid = isset($params['pid'])?$params['pid']:0;
		if($pid==0){
			$scene = 'Consult.home_submit';
		}else{
			$scene = 'Consult.home_reply';
		}
		$validate = $this->validate($params,$scene);
		if(true!==$validate){
			$this->error($validate);
		}

		$title = $params['title'];
		$content = $params['content'];
		$post_time = $params['post_time'];

		$data = [
			'uid' => UID,
			'pid' => $pid,
			'title' => $title,
			'content' => $content,
			'post_time' => $post_time
		];

		if(model('consult')->save($data)){
			$this->success('提交成功');
		}else{
			$this->error('提交失败');
		}

	}

}